import pytest
from typing import Any
from src.utils.log import logger


def pytest_addoption(parser) -> None:
    parser.addoption(
        "--env",
        default="test",
        choices=["develop", "test", "production"],
        help="Enviroment parameter.",
    )


@pytest.fixture(scope="session")
def env(request) -> str:
    """
    运行环境的fixture.
    :param request: fixture的请求上下文
    :return: 环境ID
    """
    environment = request.config.getoption("--env")
    logger.info(f"开始执行测试，当前环境：{environment}")
    return environment


@pytest.fixture(scope="session")
def params(request) -> Any:
    """
    获取参数化列表的中请求数据。
    :param request: fixture的请求上下文
    :return:
    """
    parameter = request.param
    logger.info(f"获取请求参数：{parameter}")
    return parameter
